package com.itwlj.controller.admin;

import com.itwlj.dto.OrderPageQueryDTO;
import com.itwlj.result.PageResult;
import com.itwlj.result.Result;
import com.itwlj.service.OrderService;
import com.itwlj.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/order")
@Api(tags = "订单相关接口")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 订单分页查询
     *
     * @param orderPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("订单分页查询")
    public Result<PageResult> page(OrderPageQueryDTO orderPageQueryDTO) {
        log.info("订单分页查询：{}", orderPageQueryDTO);
        PageResult pageResult = orderService.pageQuery(orderPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除订单
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除订单")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("批量删除订单：{}", ids);
        orderService.softDeleteBatch(ids);
        return Result.success();
    }

    /**
     * 根据id查询订单
     *
     * @param id
     * @return
     */
    @GetMapping
    @ApiOperation("根据id查询订单")
    public Result<OrderVO> getOrder(Long id) {
        log.info("根据id查询订单：{}", id);
        OrderVO orderVO = orderService.getById(id);
        return Result.success(orderVO);
    }

    /**
     * 订单发货
     *
     * @param id
     * @return
     */
    @PutMapping("/ship")
    @ApiOperation("订单发货")
    public Result shipOrder(Long id) {
        log.info("订单发货：{}", id);
        orderService.shipOrder(id);
        return Result.success();
    }

    /**
     * 订单运输
     *
     * @param id
     * @return
     */
    @PutMapping("/transport")
    @ApiOperation("订单运输")
    public Result transportOrder(Long id) {
        log.info("订单运输：{}", id);
        orderService.transportOrder(id);
        return Result.success();
    }

    /**
     * 取消订单
     *
     * @param id
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(Long id) {
        log.info("取消订单：{}", id);
        orderService.cancelOrder(id);
        return Result.success();
    }
}
